package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.model.entity.*;
import com.atguigu.lease.web.admin.mapper.*;
import com.atguigu.lease.web.admin.service.LeaseAgreementService;
import com.atguigu.lease.web.admin.service.RoomInfoService;
import com.atguigu.lease.web.admin.vo.agreement.AgreementQueryVo;
import com.atguigu.lease.web.admin.vo.agreement.AgreementVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.j2objc.annotations.AutoreleasePool;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author liubo
 * @description 针对表【lease_agreement(租约信息表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
public class LeaseAgreementServiceImpl extends ServiceImpl<LeaseAgreementMapper, LeaseAgreement>
        implements LeaseAgreementService {
	@Autowired
	private LeaseAgreementMapper leaseAgreementMapper;

	@Autowired
	private RoomInfoMapper roomInfoMapper;

	@Autowired
	private PaymentTypeMapper paymentTypeMapper;

	@Autowired
	private LeaseTermMapper leaseTermMapper;

	@Autowired
	private ApartmentInfoMapper apartmentInfoMapper;


	@Override
	public IPage<AgreementVo> pageInfo(Page<AgreementVo> agreementVoPage, AgreementQueryVo queryVo) {
		return leaseAgreementMapper.pageInfo(agreementVoPage,queryVo);
	}

	@Override
	public AgreementVo getInfoById(Long id) {
		LeaseAgreement leaseAgreement = this.getById(id);
		AgreementVo agreementVo = new AgreementVo();

		BeanUtils.copyProperties(leaseAgreement, agreementVo);

		ApartmentInfo apartmentInfo = apartmentInfoMapper.selectById(leaseAgreement.getApartmentId());
		RoomInfo roomInfo = roomInfoMapper.selectById(leaseAgreement.getRoomId());
		PaymentType paymentType = paymentTypeMapper.selectById(leaseAgreement.getPaymentTypeId());
		LeaseTerm leaseTerm = leaseTermMapper.selectById(leaseAgreement.getLeaseTermId());

		agreementVo.setApartmentInfo(apartmentInfo);
		agreementVo.setRoomInfo(roomInfo);
		agreementVo.setPaymentType(paymentType);
		agreementVo.setLeaseTerm(leaseTerm);

		return agreementVo;
	}
}




